<?php
namespace Api\SA;


class Ldap {

    /**
     * ldap登陆验证方法
     *
     * @param string $username 用户名
     * @param string $password 密码
     *
     * @return bool
     * @throws \Exception
     */
    public function login($username, $password) {
        $data = array(
            'username' => $username,
            'password' => $password,
            'app'      => APP_NAME,
            'ip'       => \S\Util\Ip::getClientIp(),
        );

        $util = new Util();
        $ret  = $util->request("api/ldap/check", $data);
        if ($ret === false) {
            $code    = $util->getCode();
            $message = $util->getMessage();
            throw new \Exception($message, $code);
        } else {
            return true;
        }
    }

}